/**
 * @Author: 安广伟
 * @Email: anguangwei@jwzh.tech
 * @Date: 2024-09-09 15:21:45
 * @LastEditTime 2024-09-09 15:21:45
 * @since: 1.0.0
 * @Version: 1.0.0
 * @Description:
 */

package com.ry.mall.server.config;

import com.ry.mall.server.controller.TokenTimeOutException;
import com.ry.mall.server.interceptor.TokenLoginAttributeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private TokenLoginAttributeInterceptor tokenLoginAttributeInterceptor; // 自动注入你的拦截器实例

    @Override

    public void addInterceptors(@NonNull InterceptorRegistry registry) {
        // 登录拦截器并设置需要拦截的路径
        registry.addInterceptor(tokenLoginAttributeInterceptor)
                .addPathPatterns("/V1/**")// 添加指定路径到拦截器
                .excludePathPatterns("/V1/user/login", "/V1/user/logout"); // 排除指定路径不被拦截
    }
}
